<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="../../template/tagedu.xhtml">

    <ui:define name="title">
        <title><h:outputText value="TAG - Novo Ator Para Humano"/></title>
        <f:metadata>
            <f:viewParam name="personage" value="#{actorForHuman.personageID}"/>
        </f:metadata>
    </ui:define>

    <ui:define name="content">
        <f:event type="preRenderComponent" listener="#{actorForHuman.initialize()}"/>
        <h:outputText styleClass="title" value="Cadastro de #{actorForHuman.getPersonageName()}"/>
        <h:form id="actorForHumanForm">
            <p:messages id="messages"/>
            <h:panelGrid columns="2">
                <h:panelGroup id="humanSearchResultGroup">
                    <p:dataTable value="#{actorForHuman.humanList}" var="human" paginator="true" rows="10" lazy="true"
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="10,25,50"
                                 selection="#{actorForHuman.human}" rowKey="#{human.id}">
                        <p:column selectionMode="single" />
                        <p:column rendered="false">
                            <h:outputText value="#{human.id}"/>
                        </p:column>
                        <p:column>
                            <p:rowToggler/>
                        </p:column>

                        <p:column filterMatchMode="contains" filterStyle="width: 200px" 
                                  filterBy="name">
                            <f:facet name="header">
                                <h:outputText value="Nome"/>
                            </f:facet>
                            <h:outputText value="#{human.name}"/>
                        </p:column>
                        <p:rowExpansion>
                            <h:panelGrid columns="2" cellpadding="4">
                                <h:outputLabel value="Nascimento: " for="birthday"/>
                                <h:outputText value="#{human.birthday.time}" id="birthday">
                                    <f:convertDateTime pattern="dd/MM/yyyy"/>
                                </h:outputText>
                                <h:outputLabel value="Endereço: " for="address"/>
                                <h:outputText value="#{human.address.street.name}, #{humanaddress.number}.
                                              #{human.address.complement}. #{human.address.zipcode.city.name}/#{human.address.zipcode.city.state.name}" id="address"/>
                                <ui:repeat value="#{actorForHuman.personAdditionalInfo(human.id)}" var="addInfo">
                                    <h:outputLabel value="#{addInfo.additionalInfoType.acronym}: "/>
                                    <h:outputText value="#{addInfo.value}"/>
                                </ui:repeat>
                            </h:panelGrid>
                        </p:rowExpansion>
                    </p:dataTable>
                </h:panelGroup>
                <h:panelGroup styleClass="pgroupActor" id="actorDataGroup">
                    <h:panelGroup styleClass="panelGrids">
                        <h:outputLabel for="activated" value="Ativação*:"/>
                        <p:inputMask id="activated" mask="99/99/9999" value="#{actorForHuman.actor.activated.time}" 
                                     required="true" requiredMessage="'Ativação' é obrigatório">
                            <f:convertDateTime pattern="dd/MM/yyyy"/>
                        </p:inputMask>

                    </h:panelGroup>    
                    <br/>
                    <h:panelGroup id="deactivatedGroup">
                        <h:outputLabel id="deactivatedLabel" rendered="#{not actorForHuman.deactivatedIsNull}" for="deactivated" value="Desativação:"/>
                        <p:inputMask id="deactivated"
                                     mask="99/99/9999" rendered="#{not actorForHuman.deactivatedIsNull}" 
                                     value="#{actorForHuman.actor.deactivated.time}"
                                     required="#{not actorForHuman.deactivatedIsNull}" 
                                     requiredMessage="'Desativação' é obrigatório">
                            <f:convertDateTime pattern="dd/MM/yyyy"/>
                        </p:inputMask>                        
                    </h:panelGroup>
                    <br/>
                    <h:outputLabel value="Sem data de desativação:" for="deactivatedIsNull"/>
                    <p:selectBooleanCheckbox  id="deactivatedIsNull" value="#{actorForHuman.deactivatedIsNull}">
                        <p:ajax onstart="statusDialog.show();" onsuccess="statusDialog.hide();" 
                                process="deactivatedIsNull" update="deactivatedGroup"/>
                    </p:selectBooleanCheckbox>
                    <br/>
                    <span class="clear"></span>
                    <h:outputLabel for="unity" value="Local*:"/>
                    <h:selectOneMenu id="unity" value="#{actorForHuman.unityForRegisterID}" 
                                     required="true" requiredMessage="'Local' é obrigatório">
                        <f:selectItems value="#{actorForHuman.unitiesForRegister}"/>                                    
                    </h:selectOneMenu>

                </h:panelGroup>
            </h:panelGrid>    
            <br/>
            <p:commandButton onstart="statusDialog.show();" onsuccess="statusDialog.hide();"
                             value="Cadastrar" ajax="true" process="@form" update="@form"
                             action="#{actorForHuman.createActor()}"/>
        </h:form>
    </ui:define>
</ui:composition>